﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Nova_DAL;
using System.Data.Common;
using System.Data;
using Nova_Common;
//添加和修改的界面
public partial class Manage_Code_Edit : System.Web.UI.Page
{


    DbCommand cmd = null;
    Nova_DAL.DbHelper access = new DbHelper();
    string strSQL = "";
    string strStroageNo = "";
    string strMType = "";
    string strPID = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {   //从前台获取入库单号，PID，和处理方式
            strStroageNo = Request["StorageNo"].ToString();
            strPID = Request["PID"].ToString();
            strMType = Request["MType"].ToString(); //MType处理方式:EDIT，添加
        }
        catch (Exception ex)
        {
        }
        if (!IsPostBack)
        {
            if (strMType == "Edit")
            {
                gv_Bind();  //文本中绑定编译前的数据
               // ibtn_Next.Visible = false;
                txt_SerialNumber.ReadOnly = true;
            }
        }

        //验证TextBox
        string strJs = "";
        strJs = "return Validate(";
        strJs += "'txt_Mat_Name','物料名称不为空','r'";
        strJs += ",'txt_Mat_Code','物料编码不为空','r'";
        //  strJs += ",'txt_S01','物料规格不为空','r'";
        strJs += ",'txt_Num','计划数量不为空','r_money'";
        strJs += ",'txt_Act_Num','实际数量不为空','r_money'";
        strJs += ");";
        ibtn_Add.Attributes.Add("onclick", strJs); //按键点击绑定不为空检测
    }

    protected void gv_Bind()
    {
        strSQL = @"SELECT TAL.PID,TAL.StockNo, TBM.Mat_Code,TBM.MAT_NAME,TAL.S05,
		TAL.Num,TAL.Act_Num,TBM.S01,TAL.TS01,TBM.Unit_Base,TBM.TM01,TBM.TM03,TBM.S02
                        FROM TAddStorage_List TAL
                        LEFT JOIN TBase_Material TBM ON TBM.MAT_CODE = TAL.MAT_CODE
                        WHERE TAL.PID='" + strPID + "'";
        cmd = access.GetSqlStringCommond(strSQL);
        DataSet ds = access.ExecuteDataSet(cmd);
        if (ds != null && ds.Tables[0].Rows.Count > 0)
        {
            txt_Mat_Name.Text = ds.Tables[0].Rows[0]["Mat_Name"].ToString();
            txt_Mat_Code.Text = ds.Tables[0].Rows[0]["Mat_Code"].ToString();
            txt_S01.Text = ds.Tables[0].Rows[0]["S01"].ToString();
            txt_TM01.Text = ds.Tables[0].Rows[0]["TM01"].ToString();
            txt_TM03.Text = ds.Tables[0].Rows[0]["TM03"].ToString();
            txt_Num.Text = ds.Tables[0].Rows[0]["Num"].ToString();
            txt_SerialNumber.Text = ds.Tables[0].Rows[0]["TS01"].ToString();
            txt_Act_Num.Text = ds.Tables[0].Rows[0]["Act_Num"].ToString();
            txt_S05.Text = ds.Tables[0].Rows[0]["S05"].ToString();
            txt_S02.Text = ds.Tables[0].Rows[0]["S02"].ToString();
        }
    }

    /// <summary>
    /// 判断该订单下是否添加过明细
    /// </summary>
    /// <param name="strSec_Mat_ID"></param>
    /// <returns></returns>
    protected int Bind(string strSec_Mat_ID)
    {
        strSQL = @"SELECT PID FROM TAddStorage_List  WHERE StockNo=@StockNo AND Mat_Code=@Mat_Code AND Sec_Mat_ID=@Sec_Mat_ID AND TS01=@TS01";
        cmd = access.GetSqlStringCommond(strSQL);
        access.AddInParameter(cmd, "@StockNo", DbType.String, strStroageNo);
        access.AddInParameter(cmd, "@Mat_Code", DbType.String, txt_Mat_Code.Text.ToString());
        access.AddInParameter(cmd, "@Sec_Mat_ID", DbType.String, strSec_Mat_ID);
        access.AddInParameter(cmd, "@TS01", DbType.String, txt_SerialNumber.Text.Trim());
        DataSet ds_TAL = access.ExecuteDataSet(cmd);
        if (ds_TAL != null && ds_TAL.Tables[0].Rows.Count > 0)
        {
            return Convert.ToInt32(ds_TAL.Tables[0].Rows[0][0].ToString());
        }
        else
        {
            return 0;
        }
    }

    protected void ibtn_Add_Click(object sender, ImageClickEventArgs e)
    {
        if (strStroageNo == "")
        {
            ShowBox.MessageBox(this.Page, "请输入订单号！");
            ibtn_Close_Click(sender, e);
            return;
        }
        else
        {
            strSQL = "SELECT StockNo FROM TBill_AddStorage WHERE StockNo='" + strStroageNo + "'";
            cmd = access.GetSqlStringCommond(strSQL);
            DataSet DSTBill_AddStorage = access.ExecuteDataSet(cmd);
            if (DSTBill_AddStorage == null || DSTBill_AddStorage.Tables[0].Rows.Count == 0)
            {
                ShowBox.MessageBox(this.Page, "请先添加入库单，再添加明细！");
                ibtn_Close_Click(sender, e);
                return;
            }
        }

        strSQL = "SELECT MAT_CODE FROM TBase_Material WHERE MAT_CODE='" + txt_Mat_Code.Text.Trim() + "'";
        cmd = access.GetSqlStringCommond(strSQL);
        DataSet ds = access.ExecuteDataSet(cmd);
        if (ds == null || ds.Tables[0].Rows.Count == 0)
        {
            ShowBox.MessageBox(this.Page, "该物料条码不存在，请先添加物料信息！");
            txt_Mat_Code.Text = "";
            txt_Mat_Code.Focus();
            return;
        }

        string strSec_Mat_ID = getSec_Mat_ID();
        int iFlag = 0;

        HttpCookie WCode = Request.Cookies["WCode"];
        HttpCookie WName = Request.Cookies["WName"];


        if (strMType != "Edit") //添加
        {
            int iCount = Bind(strSec_Mat_ID);

            if (iCount > 0) //该入库单下面已经添加过该物料明细，直接修改数量
            {
                strSQL = @"UPDATE TAddStorage_List SET Num=Num+'" + Convert.ToDecimal(txt_Num.Text.ToString()) + "', Act_Num=Act_Num+'" + Convert.ToDecimal(txt_Act_Num.Text.ToString()) + "' WHERE PID='" + iCount + "'";
            }
            else
            {
                strSQL = @"Insert into TAddStorage_List(
                           StockNo,Mat_Code,Num,Act_Num,Sec_Mat_ID,
                           DynamicState01,DynamicState02,DynamicState03,DynamicState04,DynamicState05,TS01,
                           TS02,TS03,TS04,TS05,S01,S02,S03,S04,S05,S06,S07,S08,S09,S10,S11,S12,S13,S14,S15,S16,S17,S18,S19,S20,
                           V01,V02,V03,V04,V05,V06,V07,V08,V09,V10,VN01,VN02,VN03,VN04,VN05,Add_Flag1,Add_Flag2,Add_Flag3,Add_Flag4) 
                           values(
                           @StockNo,@Mat_Code,@Num,@Act_Num,@Sec_Mat_ID,
                           @DynamicState01,@DynamicState02,@DynamicState03,@DynamicState04,@DynamicState05,@TS01,
                           @TS02,@TS03,@TS04,@TS05,@S01,@S02,@S03,@S04,@S05,@S06,@S07,@S08,@S09,@S10,@S11,@S12,@S13,@S14,@S15,@S16,@S17,@S18,@S19,@S20,
                           @V01,@V02,@V03,@V04,@V05,@V06,@V07,@V08,@V09,@V10,@VN01,@VN02,@VN03,@VN04,@VN05,@Add_Flag1,@Add_Flag2,@Add_Flag3,@Add_Flag4)";
            }
        }
        else  //修改入库明细
        {
            strSQL = @"UPDATE TAddStorage_List SET Mat_Code=@Mat_Code,Num=@Num,Act_Num=@Act_Num,Sec_Mat_ID=@Sec_Mat_ID,DynamicState01=@DynamicState01,DynamicState02=@DynamicState02,DynamicState03=@DynamicState03,DynamicState04=@DynamicState04,DynamicState05=@DynamicState05,TS01=@TS01,
TS02=@TS02,TS03=@TS03,TS04=@TS04,TS05=@TS05,S01=@S01,S02=@S02,S03=@S03,S04=@S04,S05=@S05,S06=@S06,S07=@S07,S08=@S08,S09=@S09,S10=@S10,S11=@S11,S12=@S12,S13=@S13,S14=@S14,S15=@S15,S16=@S16,S17=@S17,S18=@S18,S19=@S19,S20=@S20,
V01=@V01,V02=@V02,V03=@V03,V04=@V04,V05=@V05,V06=@V06,V07=@V07,V08=@V08,V09=@V09,V10=@V10,VN01=@VN01,VN02=@VN02,VN03=@VN03,VN04=@VN04,VN05=@VN05,Add_Flag1=@Add_Flag1,Add_Flag2=@Add_Flag2,Add_Flag3=@Add_Flag3,Add_Flag4=@Add_Flag4 WHERE PID=@PID";
        }
        cmd = access.GetSqlStringCommond(strSQL);
        access.AddInParameter(cmd, "@StockNo", DbType.String, strStroageNo);
        access.AddInParameter(cmd, "@Mat_Code", DbType.String, txt_Mat_Code.Text.ToString());
        access.AddInParameter(cmd, "@Num", DbType.Decimal, Convert.ToDecimal(txt_Num.Text.ToString()));
        access.AddInParameter(cmd, "@Act_Num", DbType.Decimal, Convert.ToDecimal(txt_Act_Num.Text.ToString()));
        access.AddInParameter(cmd, "@Sec_Mat_ID", DbType.String, strSec_Mat_ID);
        access.AddInParameter(cmd, "@DynamicState01", DbType.Int16, 0);
        access.AddInParameter(cmd, "@DynamicState02", DbType.Int16, 0);
        access.AddInParameter(cmd, "@DynamicState03", DbType.Int16, 0);
        access.AddInParameter(cmd, "@DynamicState04", DbType.Int16, 0);
        access.AddInParameter(cmd, "@DynamicState05", DbType.Int16, 0);
        access.AddInParameter(cmd, "@TS01", DbType.String, txt_SerialNumber.Text.Trim());
        access.AddInParameter(cmd, "@TS02", DbType.String, WCode.Value.ToString().Trim());
        access.AddInParameter(cmd, "@TS03", DbType.String, HttpUtility.UrlDecode(WName.Value.ToString().Trim()));
        access.AddInParameter(cmd, "@TS04", DbType.String, "");
        access.AddInParameter(cmd, "@TS05", DbType.String, "");
        access.AddInParameter(cmd, "@S01", DbType.String, "");
        access.AddInParameter(cmd, "@S02", DbType.String, "");
        access.AddInParameter(cmd, "@S03", DbType.String, "");
        access.AddInParameter(cmd, "@S04", DbType.String, "");
        access.AddInParameter(cmd, "@S05", DbType.String, txt_S05.Text.Trim());
        access.AddInParameter(cmd, "@S06", DbType.String, "");
        access.AddInParameter(cmd, "@S07", DbType.String, "");
        access.AddInParameter(cmd, "@S08", DbType.String, "");
        access.AddInParameter(cmd, "@S09", DbType.String, "");
        access.AddInParameter(cmd, "@S10", DbType.String, "");
        access.AddInParameter(cmd, "@S11", DbType.String, "");
        access.AddInParameter(cmd, "@S12", DbType.String, "");
        access.AddInParameter(cmd, "@S13", DbType.String, "");
        access.AddInParameter(cmd, "@S14", DbType.String, "");
        access.AddInParameter(cmd, "@S15", DbType.String, "");
        access.AddInParameter(cmd, "@S16", DbType.String, "");
        access.AddInParameter(cmd, "@S17", DbType.String, "");
        access.AddInParameter(cmd, "@S18", DbType.String, "");
        access.AddInParameter(cmd, "@S19", DbType.String, "");
        access.AddInParameter(cmd, "@S20", DbType.String, "");
        access.AddInParameter(cmd, "@V01", DbType.String, "");
        access.AddInParameter(cmd, "@V02", DbType.String, "");
        access.AddInParameter(cmd, "@V03", DbType.String, "");
        access.AddInParameter(cmd, "@V04", DbType.String, "");
        access.AddInParameter(cmd, "@V05", DbType.String, "");
        access.AddInParameter(cmd, "@V06", DbType.String, "");
        access.AddInParameter(cmd, "@V07", DbType.String, "");
        access.AddInParameter(cmd, "@V08", DbType.String, "");
        access.AddInParameter(cmd, "@V09", DbType.String, "");
        access.AddInParameter(cmd, "@V10", DbType.String, "");
        access.AddInParameter(cmd, "@VN01", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@VN02", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@VN03", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@VN04", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@VN05", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@Add_Flag1", DbType.Int16, 0);
        access.AddInParameter(cmd, "@Add_Flag2", DbType.Int16, 0);
        access.AddInParameter(cmd, "@Add_Flag3", DbType.Int16, 0);
        access.AddInParameter(cmd, "@Add_Flag4", DbType.Int16, 0);
        access.AddInParameter(cmd, "@PID", DbType.String, strPID);
        iFlag = access.ExecuteNonQuery(cmd);
        if (iFlag > 0)
        {
            if (strMType == "")
            {
                ShowBox.MessageBox(this.Page, "添加成功！");
            }
            else
            {
                ShowBox.MessageBox(this.Page, "修改成功！");
            }

            ibtn_Close_Click(sender, e);
        }
        else
        {
            if (strMType == "")
            {
                ShowBox.MessageBox(this.Page, "添加失败！");
            }
            else
            {
                ShowBox.MessageBox(this.Page, "修改失败！");
            }

            //  ibtn_Close_Click(sender, e);
        }
    }

    /// <summary>
    /// 关闭
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtn_Close_Click(object sender, ImageClickEventArgs e)
    {
        // this.Page.ClientScript.RegisterStartupScript(typeof(string), "Nova1", "window.returnValue='" + strStroageNo.ToString().Trim() + "';top.close();", true);
        this.Page.ClientScript.RegisterStartupScript(typeof(string), "Nova1", "window.opener.document.getElementById('hidden').value='" + strStroageNo.ToString().Trim() + "';window.opener.document.getElementById('form1').submit();top.close();", true);
    }


    /// <summary>
    /// 生成二级编码 
    /// </summary>
    /// <param name="i"></param>
    /// <returns></returns>
    protected string getSec_Mat_ID()
    {

        HttpCookie WCode = Request.Cookies["WCode"];
        HttpCookie WName = Request.Cookies["WName"];

        cmd = access.GetStoredProcCommond("SP_Get_Sec_Mat_ID");
        access.AddInParameter(cmd, "@Mat_Code", DbType.String, txt_Mat_Code.Text.Trim());
        access.AddInParameter(cmd, "@D01", DbType.String, "");
        access.AddInParameter(cmd, "@D02", DbType.String, "");
        access.AddInParameter(cmd, "@D03", DbType.String, "");
        access.AddInParameter(cmd, "@D04", DbType.String, "");
        access.AddInParameter(cmd, "@D05", DbType.String, "");
        access.AddInParameter(cmd, "@D06", DbType.String, "");
        access.AddInParameter(cmd, "@D07", DbType.String, "");
        access.AddInParameter(cmd, "@D08", DbType.String, "");
        access.AddInParameter(cmd, "@D09", DbType.String, "");
        access.AddInParameter(cmd, "@D10", DbType.String, "");
        //access.AddInParameter(cmd, "@S01", DbType.String, WCode.Value.ToString().Trim());
        //access.AddInParameter(cmd, "@S02", DbType.String, HttpUtility.UrlDecode(WName.Value.ToString().Trim()));
        access.AddInParameter(cmd, "@S01", DbType.String, "");
        access.AddInParameter(cmd, "@S02", DbType.String, "");
        access.AddInParameter(cmd, "@S03", DbType.String, "");
        access.AddInParameter(cmd, "@S04", DbType.String, "");
        access.AddInParameter(cmd, "@S05", DbType.String, "");
        access.AddInParameter(cmd, "@S06", DbType.String, "");
        access.AddInParameter(cmd, "@S07", DbType.String, "");
        access.AddInParameter(cmd, "@S08", DbType.String, "");
        access.AddInParameter(cmd, "@S09", DbType.String, "");
        access.AddInParameter(cmd, "@S10", DbType.String, "");
        access.AddInParameter(cmd, "@S11", DbType.String, "");
        access.AddInParameter(cmd, "@S12", DbType.String, "");
        access.AddInParameter(cmd, "@S13", DbType.String, "");
        access.AddInParameter(cmd, "@S14", DbType.String, "");
        access.AddInParameter(cmd, "@S15", DbType.String, "");
        access.AddInParameter(cmd, "@S16", DbType.String, "");
        access.AddInParameter(cmd, "@S17", DbType.String, "");
        access.AddInParameter(cmd, "@S18", DbType.String, "");
        access.AddInParameter(cmd, "@S19", DbType.String, "");
        access.AddInParameter(cmd, "@S20", DbType.String, "");
        access.AddInParameter(cmd, "@N01", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@N02", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@N03", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@N04", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@N05", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@N06", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@N07", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@N08", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@N09", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@N10", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@DynamicState01", DbType.Int16, 0);
        access.AddInParameter(cmd, "@DynamicState02", DbType.Int16, 0);
        access.AddInParameter(cmd, "@DynamicState03", DbType.Int16, 0);
        access.AddInParameter(cmd, "@DynamicState04", DbType.Int16, 0);
        access.AddInParameter(cmd, "@DynamicState05", DbType.Int16, 0);
        access.AddInParameter(cmd, "@TS01", DbType.String, txt_SerialNumber.Text.Trim());
        access.AddInParameter(cmd, "@TS02", DbType.String, "");
        access.AddInParameter(cmd, "@TS03", DbType.String, "");
        access.AddInParameter(cmd, "@TS04", DbType.String, "");
        access.AddInParameter(cmd, "@TS05", DbType.String, "");
        access.AddInParameter(cmd, "@ForceNew", DbType.Int16, 1); //如果不存在2级码，强迫创建新的
                                                                  //access.AddInParameter(cmd, "@UserName", DbType.String, Request.Cookies["vNovaUserNo"].Value.ToString());
        access.AddInParameter(cmd, "@UserName", DbType.String, "");//单画面调试用，单画面调试不然Request.Cookies["vNovaUserNo"].Value.ToString())报错
        access.AddOutParameter(cmd, "@Sec_Mat_ID", DbType.Int32, 20);
        access.AddOutParameter(cmd, "@ResNO", DbType.Int16, 10);
        access.AddOutParameter(cmd, "@ResMsg", DbType.String, 255);
        access.ExecuteNonQuery(cmd);
        int iSecs = Convert.ToInt32(access.GetParameter(cmd, "@Sec_Mat_ID").Value.ToString());
        string strSecs = iSecs.ToString();
        return strSecs;

    }
    protected void ibtn_Next_Click(object sender, ImageClickEventArgs e)
    {
        HttpCookie WCode = Request.Cookies["WCode"];
        HttpCookie WName = Request.Cookies["WName"];

        if (strStroageNo == "")
        {
            ShowBox.MessageBox(this.Page, "请输入订单号！");
            ibtn_Close_Click(sender, e);
            return;
        }
        else
        {
            strSQL = "SELECT StockNo FROM TBill_AddStorage WHERE StockNo='" + strStroageNo + "'";
            cmd = access.GetSqlStringCommond(strSQL);
            DataSet DSTBill_AddStorage = access.ExecuteDataSet(cmd);
            if (DSTBill_AddStorage == null || DSTBill_AddStorage.Tables[0].Rows.Count == 0)
            {
                ShowBox.MessageBox(this.Page, "请先添加入库单，再添加明细！");
                ibtn_Close_Click(sender, e);
                return;
            }
        }

        strSQL = "SELECT MAT_CODE FROM TBase_Material WHERE MAT_CODE='" + txt_Mat_Code.Text.Trim() + "'";
        cmd = access.GetSqlStringCommond(strSQL);
        DataSet ds = access.ExecuteDataSet(cmd);
        if (ds == null || ds.Tables[0].Rows.Count == 0)
        {
            ShowBox.MessageBox(this.Page, "该物料条码不存在，请先添加物料信息！");
            txt_Mat_Code.Text = "";
            txt_Mat_Code.Focus();
            return;
        }

        string strSec_Mat_ID = getSec_Mat_ID();
        int iFlag = 0;


        if (strMType != "Edit")
        {
            int iCount = Bind(strSec_Mat_ID);

            if (iCount > 0)
            {
                strSQL = @"UPDATE TAddStorage_List SET Num=Num+'" + Convert.ToDecimal(txt_Num.Text.ToString()) + "', Act_Num=Act_Num+'" + Convert.ToDecimal(txt_Act_Num.Text.ToString()) + "' WHERE PID='" + iCount + "'";
            }
            else
            {
                strSQL = @"Insert into TAddStorage_List(StockNo,Mat_Code,Num,Act_Num,Sec_Mat_ID,DynamicState01,DynamicState02,DynamicState03,DynamicState04,DynamicState05,TS01,
TS02,TS03,TS04,TS05,S01,S02,S03,S04,S05,S06,S07,S08,S09,S10,S11,S12,S13,S14,S15,S16,S17,S18,S19,S20,
V01,V02,V03,V04,V05,V06,V07,V08,V09,V10,VN01,VN02,VN03,VN04,VN05,Add_Flag1,Add_Flag2,Add_Flag3,Add_Flag4) values(@StockNo,@Mat_Code,@Num,@Act_Num,@Sec_Mat_ID,@DynamicState01,@DynamicState02,@DynamicState03,@DynamicState04,@DynamicState05,@TS01,
@TS02,@TS03,@TS04,@TS05,@S01,@S02,@S03,@S04,@S05,@S06,@S07,@S08,@S09,@S10,@S11,@S12,@S13,@S14,@S15,@S16,@S17,@S18,@S19,@S20,
@V01,@V02,@V03,@V04,@V05,@V06,@V07,@V08,@V09,@V10,@VN01,@VN02,@VN03,@VN04,@VN05,@Add_Flag1,@Add_Flag2,@Add_Flag3,@Add_Flag4)";
            }
        }
        else
        {
            strSQL = @"UPDATE TAddStorage_List SET Mat_Code=@Mat_Code,Num=@Num,Act_Num=@Act_Num,Sec_Mat_ID=@Sec_Mat_ID,DynamicState01=@DynamicState01,DynamicState02=@DynamicState02,DynamicState03=@DynamicState03,DynamicState04=@DynamicState04,DynamicState05=@DynamicState05,TS01=@TS01,
TS02=@TS02,TS03=@TS03,TS04=@TS04,TS05=@TS05,S01=@S01,S02=@S02,S03=@S03,S04=@S04,S05=@S05,S06=@S06,S07=@S07,S08=@S08,S09=@S09,S10=@S10,S11=@S11,S12=@S12,S13=@S13,S14=@S14,S15=@S15,S16=@S16,S17=@S17,S18=@S18,S19=@S19,S20=@S20,
V01=@V01,V02=@V02,V03=@V03,V04=@V04,V05=@V05,V06=@V06,V07=@V07,V08=@V08,V09=@V09,V10=@V10,VN01=@VN01,VN02=@VN02,VN03=@VN03,VN04=@VN04,VN05=@VN05,Add_Flag1=@Add_Flag1,Add_Flag2=@Add_Flag2,Add_Flag3=@Add_Flag3,Add_Flag4=@Add_Flag4 WHERE PID=@PID";
        }
        cmd = access.GetSqlStringCommond(strSQL);
        access.AddInParameter(cmd, "@StockNo", DbType.String, strStroageNo);
        access.AddInParameter(cmd, "@Mat_Code", DbType.String, txt_Mat_Code.Text.ToString());
        access.AddInParameter(cmd, "@Num", DbType.Decimal, Convert.ToDecimal(txt_Num.Text.ToString()));
        access.AddInParameter(cmd, "@Act_Num", DbType.Decimal, Convert.ToDecimal(txt_Act_Num.Text.ToString()));
        access.AddInParameter(cmd, "@Sec_Mat_ID", DbType.String, strSec_Mat_ID);
        access.AddInParameter(cmd, "@DynamicState01", DbType.Int16, 0);
        access.AddInParameter(cmd, "@DynamicState02", DbType.Int16, 0);
        access.AddInParameter(cmd, "@DynamicState03", DbType.Int16, 0);
        access.AddInParameter(cmd, "@DynamicState04", DbType.Int16, 0);
        access.AddInParameter(cmd, "@DynamicState05", DbType.Int16, 0);
        access.AddInParameter(cmd, "@TS01", DbType.String, "");
        access.AddInParameter(cmd, "@TS02", DbType.String, WCode.Value.ToString().Trim());
        access.AddInParameter(cmd, "@TS03", DbType.String, HttpUtility.UrlDecode(WName.Value.ToString().Trim()));
        access.AddInParameter(cmd, "@TS04", DbType.String, "");
        access.AddInParameter(cmd, "@TS05", DbType.String, "");
        access.AddInParameter(cmd, "@S01", DbType.String, "");
        access.AddInParameter(cmd, "@S02", DbType.String, "");
        access.AddInParameter(cmd, "@S03", DbType.String, "");
        access.AddInParameter(cmd, "@S04", DbType.String, "");
        access.AddInParameter(cmd, "@S05", DbType.String, "");
        access.AddInParameter(cmd, "@S06", DbType.String, "");
        access.AddInParameter(cmd, "@S07", DbType.String, "");
        access.AddInParameter(cmd, "@S08", DbType.String, "");
        access.AddInParameter(cmd, "@S09", DbType.String, "");
        access.AddInParameter(cmd, "@S10", DbType.String, "");
        access.AddInParameter(cmd, "@S11", DbType.String, "");
        access.AddInParameter(cmd, "@S12", DbType.String, "");
        access.AddInParameter(cmd, "@S13", DbType.String, "");
        access.AddInParameter(cmd, "@S14", DbType.String, "");
        access.AddInParameter(cmd, "@S15", DbType.String, "");
        access.AddInParameter(cmd, "@S16", DbType.String, "");
        access.AddInParameter(cmd, "@S17", DbType.String, "");
        access.AddInParameter(cmd, "@S18", DbType.String, "");
        access.AddInParameter(cmd, "@S19", DbType.String, "");
        access.AddInParameter(cmd, "@S20", DbType.String, "");
        access.AddInParameter(cmd, "@V01", DbType.String, "");
        access.AddInParameter(cmd, "@V02", DbType.String, "");
        access.AddInParameter(cmd, "@V03", DbType.String, "");
        access.AddInParameter(cmd, "@V04", DbType.String, "");
        access.AddInParameter(cmd, "@V05", DbType.String, "");
        access.AddInParameter(cmd, "@V06", DbType.String, "");
        access.AddInParameter(cmd, "@V07", DbType.String, "");
        access.AddInParameter(cmd, "@V08", DbType.String, "");
        access.AddInParameter(cmd, "@V09", DbType.String, "");
        access.AddInParameter(cmd, "@V10", DbType.String, "");
        access.AddInParameter(cmd, "@VN01", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@VN02", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@VN03", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@VN04", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@VN05", DbType.Decimal, 0);
        access.AddInParameter(cmd, "@Add_Flag1", DbType.Int16, 0);
        access.AddInParameter(cmd, "@Add_Flag2", DbType.Int16, 0);
        access.AddInParameter(cmd, "@Add_Flag3", DbType.Int16, 0);
        access.AddInParameter(cmd, "@Add_Flag4", DbType.Int16, 0);
        access.AddInParameter(cmd, "@PID", DbType.String, strPID);
        iFlag = access.ExecuteNonQuery(cmd);
        if (iFlag > 0)
        {
            txt_Mat_Code.Text = "";
            txt_Mat_Name.Text = "";
            txt_Num.Text = "0";
           // txt_S01.Text = "";
        }
        else
        {
            if (strMType == "")
            {
                ShowBox.MessageBox(this.Page, "添加失败！");
            }
            else
            {
                ShowBox.MessageBox(this.Page, "修改失败！");
            }
        }
    }
}
